"""
======================
@author:SUNLIN
@time:2025/3/10 19:57
@email:1232@163.com
======================
"""

import pandas as pd

# 禁止换行显示
pd.set_option('display.expand_frame_repr', False)
# 显示所有行
pd.set_option('display.max_rows', None)
# 显示所有列
pd.set_option('display.max_columns', None)
# 设置数据的显示长度，默认为50
pd.set_option('display.width', 10)

data = pd.read_excel("../doc/datasource/C8-8.3-数据采集.xlsx",
                     usecols=['type_list', 'average_score', 'language', 'release_date', 'movie_name', 'country','number_of_people'])

print(data)
# 查重、去重：title
# 检查是否有重复数据
dupl_df = data.duplicated('movie_name')
## 对数据进行去重
dupl_data = data.drop_duplicates('movie_name')
print('去重之后的数据\n', dupl_data)

# 缺失值的处理

nan_df = pd.isna(dupl_data)
print('查询缺失的值\n', nan_df)
print('average列的均值\n', dupl_data['average_score'].mean())

# 这种方式给列赋值会出错：dupl_data['average'] = dupl_data['average'].fillna(value=dupl_data['average'].mean())
dupl_data.loc[:, 'average_score'] = dupl_data['average_score'].fillna(value=dupl_data['average_score'].mean().round(3))

print('赋值后的列数据\n', dupl_data['average_score'])

# 分列
# 只获得日期数据
dupl_data.loc[:, 'release_date'] = dupl_data['release_date'].str.split('(', expand=True)[0]
print(dupl_data)

df = pd.DataFrame(dupl_data)

print(df)

df.to_excel("../doc/datasource/C8-8.5-数据采集-clean.xlsx")
